package com.crl.module.cmpRpc.factory
{
	import com.crl.core.config.section.model.ConnectionStringSetting;
	import com.crl.module.cmpRpc.behavior.AbstractRequestBehavior;
	import com.crl.module.cmpRpc.behavior.HttpRequest;
	
	import flash.utils.Dictionary;
	
	
	
	/**
	 *  策略工厂创建类(简单工厂,主要提供一个类型创建的统一位置)
	 * @author crl 
	 * 
	 */	
	public class ServiceFactory
	{
		
		
		private static var factorys:Dictionary=new Dictionary;
		
		public static function create(connectStringSetting:ConnectionStringSetting):AbstractRequestBehavior{
			
			var factory:IRequestorFactory=factorys[connectStringSetting.name];
			
			if(factory)return factory.createRequestBehavior();
			
			switch(connectStringSetting.providerName.toLowerCase()){
				case "amf" :
					factory=new AMFRequestFactory(connectStringSetting);
					break;
				case "webService" :
					factory=new WebServiceRequestFactory(connectStringSetting);
					break;
				case "http" :
					return new HttpRequest(connectStringSetting.connectionString);
					break;
				case "socket" :
					//factory=new soc
					break;
			}
			
			factorys[connectStringSetting.name]=factory;
			
			return factory.createRequestBehavior();
		}
	}
}